import { cloneObj } from 'common/js/util';

//应用系统管理
export function ApplicationThead(that) {
	return [{
		type: 'index',
		width: 60,
		align: 'center'
	}, {
		title: '应用系统ID',
		key: 'systemId',
		width: 120,
		align: 'center'
	}, {
		title: '应用系统名称',
		key: 'appName'
	}, {
		title: '项目名称',
		key: 'projectName'
	}, {
		title: '备注',
		key: 'remark'
	}, {
		title: '操作',
		key: 'action',
		width: 130,
		align: 'center',
		render: (h, params) => {
			return h('div', [
				h('Button', {
					props: {
						type: 'primary',
						size: 'small'
					},
					style: {
						marginRight: '5px'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row)
							that.edit(data);
						}
					}
				}, '修改'),
				h('Button', {
					props: {
						type: 'error',
						size: 'small'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row)
							that.del(data);
						}
					}
				}, '删除')
			]);
		}
	}]
}

//接口管理
export function InterfaceThead(that) {
	return [{
		type: 'index',
		width: 60,
		align: 'center'
	}, {
		title: '接口名称',
		key: 'apiName'
	}, {
		title: '所属系统',
		key: 'appNamesList',
		render: (h, params) => {
			let str = params.row.appNamesList.join('、');
			return h('span', {}, str);
		}
	}, {
		title: '接口地址',
		key: 'apiUrl'
	}, {
		title: '接口action',
		key: 'apiAction'
	}, {
		title: '接口参数',
		key: 'apiParams'
	}, {
		title: '接口返回',
    key: 'apiResult',
    render: (h, params) => {
			let str = params.row.apiResult;
			return h('div', {
        style: {
          overflow: 'hidden',
          textOverflow: 'ellipsis',
          whiteSpace: 'nowrap'
        }
      }, str);
		}
	}, {
		title: '创建时间',
		key: 'createDate'
	}, {
		title: '修改时间',
		key: 'editDate'
	}, {
		title: '备注',
		key: 'remark'
	}, {
		title: '操作',
		key: 'action',
		width: 130,
		render: (h, params) => {
			return h('div', [
				h('Button', {
					props: {
						type: 'primary',
						size: 'small'
					},
					style: {
						marginRight: '5px'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.edit(data);
						}
					}
				}, '修改'),
				h('Button', {
					props: {
						type: 'error',
						size: 'small'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.del(data);
						}
					}
				}, '删除')
			]);
		}
	}]
}

//修改日志
export function ModificationLogThead(that) {
	return [{
		type: 'index',
		width: 60,
		align: 'center'
	}, {
		title: '所属系统',
		key: 'appNamesList',
		render: (h, params) => {
			let str = params.row.appNamesList.join('、');
			return h('span', {}, str);
		}
	}, {
		title: '修改内容',
		key: 'info'
	}, {
		title: '创建时间',
		key: 'createDate',
		align: 'center',
		width: 150
	}, {
		title: '修改时间',
		key: 'editDate',
		align: 'center',
		width: 150
	}, {
		title: '操作',
		key: 'action',
		align: 'center',
		width: 130,
		render: (h, params) => {
			return h('div', [
				h('Button', {
					props: {
						type: 'primary',
						size: 'small'
					},
					style: {
						marginRight: '5px'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.edit(data);
						}
					}
				}, '修改'),
				h('Button', {
					props: {
						type: 'error',
						size: 'small'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.del(data);
						}
					}
				}, '删除')
			]);
		}
	}]
}

//接口请求日志
export function InterfaceLogThead() {
	return [{
		type: 'index',
		width: 60,
		align: 'center'
	}, {
		title: '接口路径',
		key: 'action_url'
	}, {
		title: '请求IP',
		key: 'RemoteAddr'
	}, {
		title: '请求用户',
		key: 'username'
	}, {
		title: '系统名称',
		key: 'appName'
	}, {
		title: '请求时间',
		key: 'time',
		align: 'center',
		width: 160
	}]
}

//应用系统服务
export function ApplicationServiceThead(that) {
	return [{
		type: 'selection',
		width: 60,
		align: 'center'
	}, {
		title: 'handler名称',
		key: 'handlerName',
		width: 100
	}, {
		title: '所属系统',
		key: 'appNamesList',
		width: 130,
		render: (h, params) => {
			let str = params.row.appNamesList.join('、');
			return h('span', {}, str);
		}
	}, {
		title: '所在服务器',
		key: 'appServer',
		align: 'center',
		width: 120,
	}, {
		title: 'handler路径',
		key: 'handlerPath',
		align: 'center',
		render: (h, params) => {
			let str = params.row.handlerPath;
			return h('span', {
				class: {
					'table-nowrap': true
				}
			}, str);
		}
	}, {
		title: '启动参数',
		key: 'runParams',
		align: 'center',
		render: (h, params) => {
			let str = params.row.runParams;
			return h('span', {
				class: {
					'table-nowrap': true
				}
			}, str);
		}
	}, {
		title: '运行状态',
		key: 'isRunning',
		align: 'center',
		width: 80,
		render: (h, params) => {
			let bol = false;
			if(params.row.isRunning) {
				bol = params.row.isRunning.isRunning;
			}
			let str = bol ? '运行中' : '未运行';

			return h('span', {
				class: {
					'table-nowrap': true,
					'table-success': bol,
					'table-error': !bol
				}
			}, str);
		}
	}, {
		title: '运行时间',
		key: 'uptime',
		align: 'center',
		width: 120
	}, {
		title: '配置文件',
		key: 'handlerConfig'
	}, {
		title: '备注',
		key: 'remark'
	}, {
		title: '操作',
		key: 'action',
		align: 'center',
		width: 180,
		render: (h, params) => {
			let bol = false;
			if(params.row.isRunning) {
				bol = params.row.isRunning.isRunning;
			}
			let str = bol ? '停止' : '启动';
			let type = bol ? 'error' : 'success';

			return h('div', [
				h('Button', {
					props: {
						type: 'primary',
						size: 'small'
					},
					style: {
						marginRight: '5px'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.edit(data)
						}
					}
				}, '修改'),
				h('Button', {
					props: {
						type: 'error',
						size: 'small'
					},
					style: {
						marginRight: '5px'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.del(data)
						}
					}
				}, '删除'),
				h('Button', {
					props: {
						type: type,
						size: 'small'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.start(data, bol);
						}
					}
				}, str)
			]);
		}
	}]
}

//服务日志
export function ServiceLogThead() {
	return [{
		type: 'index',
		width: 60,
		align: 'center'
	}, {
		title: 'action名称',
		key: 'handlerName'
	}, {
		title: '类名',
		key: 'appNamesList'
	}, {
		title: '参数',
		key: 'appServer'
	}, {
		title: '等级',
		key: 'handlerPath'
	}, {
		title: '返回状态',
		key: 'runParams'
	}, {
		title: '信息',
		key: 'isRunning',

	}, {
		title: '请求时间',
		key: 'uptime'
	}]
}

//任务日志
export function TaskThead(that) {
	return [{
		type: 'index',
		width: 60,
		align: 'center'
	}, {
		title: '任务名称',
		key: 'taskName',
		width: 120
	}, {
		title: '任务类型',
		key: 'logType',
		width: 60,
		align: 'center'
	}, {
		title: '数据量',
		key: 'dataSize',
		width: 150,
		align: 'center'
	}, {
		title: '数据大小(B)',
		key: 'dataByte',
		width: 80,
		align: 'center'
	}, {
		title: '日志时间',
		key: 'logTime',
		width: 130,
		align: 'center'
	}, {
		title: '信息',
		key: 'info',
		render: (h, params) => {
			let str = params.row.info;
			return h('div', [
				h('span', {
					class: {
						'table-nowrap': true
					}
				}, str),
				h('div', {
					class: {
						'table-nowrap': true
					},
					style: {
						color: 'green',
						cursor: 'pointer'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.infoDetailClick(data)
						}
					}
				}, '详情'),
			])
		}
	}, {
		title: '状态',
		key: 'result',
		width: 60,
		align: 'center',
		render: (h, params) => {
			let str = params.row.result;
			let isSuccess = true;
			if(str === '失败') {
				isSuccess = false;
			}
			return h('span', {
				class: {
					'table-nowrap': true,
					'table-success': isSuccess,
					'table-error': !isSuccess
				}
			}, str);
		}
	}]
}

//文档管理
export function DocumentThead(that) {
	return [{
		type: 'index',
		width: 60,
		align: 'center'
	}, {
		title: '文件名称',
		key: 'fileName',
		align: 'center',
		width: 160
	}, {
		title: '所属系统',
		key: 'appNamesList',
		render: (h, params) => {
			let str = params.row.appNamesList.join('、');
			return h('span', {}, str);
		}
	}, {
		title: '文件路径',
		key: 'filePath'
	}, {
		title: '上传时间',
		key: 'createTime',
		width: 160,
		align: 'center'
	}, {
		title: '备注',
		key: 'remark'
	}, {
		title: '操作',
		key: 'action',
		align: 'center',
		width: 180,
		render: (h, params) => {
			return h('div', [
				h('Button', {
					props: {
						type: 'primary',
						size: 'small'
					},
					style: {
						marginRight: '5px'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.edit(data);
						}
					}
				}, '修改'),
				h('Button', {
					props: {
						type: 'error',
						size: 'small'
					},
					style: {
						marginRight: '5px'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.del(data);
						}
					}
				}, '删除'),
				h('Button', {
					props: {
						type: 'text',
						size: 'small'
					},
					style: {
						textDecoration: 'underline',
						color: 'blue'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.down(data);
						}
					}
				}, '下载')
			]);
		}
	}]
}

//用户管理
export function UserThead(that) {
	return [{
		type: 'index',
		width: 60,
		align: 'center'
	}, {
		title: '用户名',
		key: 'userName',
		width: 120,
		align: 'center'
	}, {
		title: '部门名称',
		key: 'departmentID',
		width: 120,
		align: 'center'
	}, {
		title: '电话',
		key: 'mobile',
		width: 120,
		align: 'center'
	}, {
		title: '角色',
		key: 'roleName',
		width: 100,
		align: 'center'
	}, {
		title: '登录时间',
		key: 'lastLoginTime',
		align: 'center'
	}, {
		title: '登陆IP',
		key: 'loginIp',
		align: 'center'
	}, {
		title: '状态',
		key: 'status',
		width: 80,
		align: 'center',
		render: (h, params) => {
			let str = '';
			let isSuccess = true;
			if(params.row.status === 1) {
				str = '启用';
			} else {
				str = '未启用';
				isSuccess = false;
			}
			return h('div', {
				class: {
					'table-success': isSuccess,
					'table-error': !isSuccess
				}
			}, str);
		}
	}, {
		title: '操作',
		key: 'action',
		align: 'center',
		width: 130,
		render: (h, params) => {
			return h('div', [
				h('Button', {
					props: {
						type: 'primary',
						size: 'small'
					},
					style: {
						marginRight: '5px'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.edit(data);
						}
					}
				}, '修改'),
				h('Button', {
					props: {
						type: 'error',
						size: 'small'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.del(data);
						}
					}
				}, '删除')
			]);
		}
	}]
}

//角色管理
export function RoleThead(that) {
	return [{
		type: 'index',
		width: 60,
		align: 'center'
	}, {
		title: '角色名',
		key: 'RoleName',
		width: 100,
		align: 'center'
	}, {
		title: '备注',
		key: 'Remark'
	}, {
		title: '操作',
		key: 'action',
		align: 'center',
		width: 180,
		render: (h, params) => {
			return h('div', [
				h('Button', {
					props: {
						type: 'primary',
						size: 'small'
					},
					style: {
						marginRight: '5px'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.edit(data);
						}
					}
				}, '修改'),
				h('Button', {
					props: {
						type: 'error',
						size: 'small'
					},
					style: {
						marginRight: '5px'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.del(data);
						}
					}
				}, '删除'),
				h('Button', {
					props: {
						type: 'primary',
						size: 'small'
					},
					on: {
						click: () => {
							let data = cloneObj(params.row);
							that.role(data);
						}
					}
				}, '权限')
			]);
		}
	}]
}

export function redisQueueThead() {
	return [{
		title: '字段',
		key: 'key',
		width: 200
	}, {
		title: '值',
		key: 'value'
	}]
}

export function DataSourceThead() {
	return [{
		title: '数据源名称',
		key: 'status',
		width: 130,
		render: (h, params) => {
			let str = params.row.fromSource.sourcename;
			return h('div', {}, str);
		}
	}, {
		title: '数据源访问地址',
		key: 'status',
		render: (h, params) => {
			let str = params.row.fromSource.link;
			return h('div', {}, str);
		}
	}, {
		title: '数据源链接类型',
		key: 'status',
		align: 'center',
		width: 130,
		render: (h, params) => {
			let str = params.row.fromSource.linktype;
			return h('div', {}, str);
		}
	}, {
		title: '任务名称',
		key: 'taskname'
	}]
}

export function TaskConfigThead() {
	return [{
		title: '数据源名称',
		key: 'status',
		width: 130,
		render: (h, params) => {
			let str = params.row.fromSource.sourcename;
			return h('div', {}, str);
		}
	}, {
		title: '数据源链接类型',
		key: 'status',
		align: 'center',
		width: 130,
		render: (h, params) => {
			let str = params.row.fromSource.linktype;
			return h('div', {}, str);
		}
	}, {
		title: '目的数据源',
		key: 'status',
		render: (h, params) => {
			let str = params.row.toSource.sourcename;
			return h('div', {}, str);
		}
	}, {
		title: '目的数据源类型',
		key: 'status',
		render: (h, params) => {
			let str = params.row.toSource.dbType;
			return h('div', {}, str);
		}
	}, {
		title: '任务名称',
		key: 'taskname'
	}, {
		title: '任务类型',
		key: 'tasktype'
	}, {
		title: '状态',
		key: 'status'
	}, {
		title: '下次执行时间',
		key: 'nextrundt'
	}, {
		title: '任务分组',
		key: 'taskgroup'
	}]
}

export function HandlerDetailedThead() {
	return [{
		title: '方法名称',
		key: 'name',
		width: 400
	}, {
		title: '方法说明',
		key: 'remake'
	}]
}

export function StrustJournalThead() {
	return [{
		title: '接口路径',
		key: 'action_url'
	}, {
		title: '请求IP',
		key: 'RemoteAddr'
	}, {
		title: '请求用户',
		key: 'username'
	}, {
		title: '系统名称',
		key: 'appName'
	}, {
		title: '请求时间',
		key: 'time'
	}]
}

export function HandlerJournalThead() {
	return [{
		type: 'index',
		width: 60,
		align: 'center'
	}, {
		title: 'action名称',
		key: 'handlerName'
	}, {
		title: '类名',
		key: 'appNamesList'
	}, {
		title: '参数',
		key: 'appServer'
	}, {
		title: '等级',
		key: 'handlerPath'
	}, {
		title: '返回状态',
		key: 'runParams'
	}, {
		title: '信息',
		key: 'isRunning',

	}, {
		title: '请求时间',
		key: 'uptime'
	}]
}

export function SystemDocumentThead(that) {
	return [{
		type: 'index',
		width: 60,
		align: 'center'
	}, {
		title: '文件名称',
		key: 'fileName',
		align: 'center',
		width: 160
	}, {
		title: '所属系统',
		key: 'appNamesList',
		render: (h, params) => {
			let str = params.row.appNamesList.join('、');
			return h('span', {}, str);
		}
	}, {
		title: '文件路径',
		key: 'filePath'
	}, {
		title: '上传时间',
		key: 'createTime',
		width: 160,
		align: 'center'
	}, {
		title: '备注',
		key: 'remark'
	}, {
		title: '操作',
		key: 'action',
		align: 'center',
		width: 120,
		render: (h, params) => {
			return h('Button', {
				props: {
					type: 'text',
					size: 'small'
				},
				style: {
					textDecoration: 'underline',
					color: 'blue'
				},
				on: {
					click: () => {
						let data = cloneObj(params.row);
						that.down(data);
					}
				}
			}, '下载');
		}
	}]
}
